package com.xjscrm.console.web.chat;

import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.console.common.util.LoginContext;
import com.xjscrm.console.dto.ChatDispatchSettingsDTO;
import com.xjscrm.console.service.customer.chat.ChatDispatchSettingsService;
import com.xjscrm.console.vo.LoginVO;
import com.xjscrm.console.vo.chat.ChatDispatchSettingsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author mingyang.chen create in 2024/3/15 11:54
 */
@Api(value = "分发设置管理", tags = "客服聊天|分发设置管理")
@RestController
@RequestMapping("/chat/dispatch_setting")
public class ChatDispatchSettingsController {

    @Autowired
    private ChatDispatchSettingsService chatDispatchSettingsService;


    @PostMapping("/get")
    @ApiOperation(value = "获取分发设置", notes = "获取分发设置", response = ChatDispatchSettingsVO.class)
    public Object get() {
        LoginVO login = LoginContext.getLogin();
        return chatDispatchSettingsService.get(login);
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改分发设置", notes = "修改分发设置", response = Boolean.class)
    public Object search(@RequestBody ChatDispatchSettingsDTO opt) {
        if (Objects.isNull(opt)) {
            throw new BusinessException("查询参数错误");
        }
        LoginVO login = LoginContext.getLogin();
        chatDispatchSettingsService.update(login, opt);
        return true;
    }
}
